package com.example.truyencotich;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;

import com.example.truyencotich.support.Global;
import com.example.truyencotich.support.SoundManager;

public class HomeActivity extends Activity implements OnClickListener {
	Button btnCayKhe, btnCayTre, btnTW, btnFB;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.home_activity);

		initView();
	}

	void initView() {
		btnCayKhe = (Button) findViewById(R.id.btnCayKhe);
		btnCayTre = (Button) findViewById(R.id.btnCayTre);
		btnTW = (Button) findViewById(R.id.btnTW);
		btnFB = (Button) findViewById(R.id.btnFB);

		btnCayKhe.setOnClickListener(this);
		btnCayTre.setOnClickListener(this);
		btnTW.setOnClickListener(this);
		btnFB.setOnClickListener(this);
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.btnCayKhe:
			Global.typeStory = 1;
			Global.sm = new SoundManager(this);
			Intent i1 = new Intent(HomeActivity.this, CayKheActivity.class);
			startActivity(i1);
			break;
		case R.id.btnCayTre:
			Global.typeStory = 2;
			Global.sm = new SoundManager(this);
			Intent i2 = new Intent(HomeActivity.this, CayTreActivity.class);
			startActivity(i2);
			break;
		case R.id.btnTW:
			Toast.makeText(getApplicationContext(), "Tweeter",
					Toast.LENGTH_SHORT).show();
			break;
		case R.id.btnFB:
			Toast.makeText(getApplicationContext(), "FaceBook",
					Toast.LENGTH_SHORT).show();
			break;
		default:
			break;
		}
	}

	@Override
	protected void onResume() {
		Global.indexCurrSong = 0;
		Global.isMute = false;
		super.onResume();
	}

	@Override
	public void onBackPressed() {
		Intent intent = new Intent(getApplicationContext(),
				DialogExitActivity.class);
		startActivityForResult(intent, Global.RESULT_CODE);
	}

	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		super.onActivityResult(requestCode, resultCode, data);
		if (resultCode == Global.RESULT_CODE)
			finish();
	}
}
